﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bob
{
public class ClassPluginMan : BilibiliDM_PluginFramework.DMPlugin {
    private CDMRecorder recorder;
    public ClassPluginMan() {
        this.Connected += Class1_Connected;
        this.Disconnected += Class1_Disconnected;
        this.ReceivedDanmaku += Class1_ReceivedDanmaku;
        this.ReceivedRoomCount += Class1_ReceivedRoomCount;
        this.PluginAuth = "樱木小白";
        this.PluginName = "弹幕输出插件";
        this.PluginCont = "sup9@qq.com";
        this.PluginVer = "v0.0.1";
        _instance = this;
        danmuPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\弹幕输出\\";
    }
    private static ClassPluginMan _instance;
    static public ClassPluginMan instance() {
        return _instance;
    }
    private void Class1_ReceivedRoomCount(object sender, BilibiliDM_PluginFramework.ReceivedRoomCountArgs e) {
        //throw new NotImplementedException();
    }

    private void Class1_ReceivedDanmaku(object sender, BilibiliDM_PluginFramework.ReceivedDanmakuArgs e) {
        //throw new NotImplementedException();
        recorder.WriteDanMu(e);
    }

    private void Class1_Disconnected(object sender, BilibiliDM_PluginFramework.DisconnectEvtArgs e) {
        //throw new NotImplementedException();
    }

    private void Class1_Connected(object sender, BilibiliDM_PluginFramework.ConnectedEvtArgs e) {
        //throw new NotImplementedException();
        CDMRecorder.category = this.RoomId.ToString();
        //recorder.Ready();
    }
    private FormG.FormX form1;
    public override void Admin() {
        base.Admin();
        Log("Hello World from admin");
        if (form1 == null) {
            form1 = new FormG.FormX();
            form1.Show();
            form1 = null;
        }
    }

    public override void Stop() {
        base.Stop();
        //請勿使用任何阻塞方法
        Log("Plugin Stoped!");
        recorder.Stop();
        recorder = null;
    }

    public override void Start() {
        base.Start();
        //請勿使用任何阻塞方法
        Log("Plugin Started!");
        recorder = new CDMRecorder(danmuPath);
        if (RoomId!=null && RoomId != 0) {
            recorder.Start();
        }
        //Log(" mydocument: " + System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
    }
    //!
    public string danmuPath
    {
        get;
        set;
    }
}
}
